package com.travel.server.manager.impl.command.order.data;

import com.travel.common.excel.ExcelData;
import com.travel.common.util.ExcelUtil;
import com.travel.server.manager.dto.request.order.data.ExportOrderDataRequest;
import com.travel.server.manager.dto.response.EmptyResponse;
import com.travel.server.manager.dto.response.order.data.QueryOrderDataResponse;
import com.travel.server.manager.dto.response.order.data.QueryOrderDataResponse.PayDataItem;
import com.travel.server.manager.impl.command.AbstractCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: LiZhenhui
 * @Date: 2018/12/7 16:22
 * @Desc:
 */
@Component
@Slf4j
public class ExportOrderDataCommand extends AbstractCommand<ExportOrderDataRequest, EmptyResponse> {

    @Autowired
    private QueryOrderDataCommand queryOrderDataCommand;

    @Override
    protected void checkInput(ExportOrderDataRequest request) {

    }

    @Override
    public EmptyResponse handle(ExportOrderDataRequest request) {

        QueryOrderDataResponse response = queryOrderDataCommand.handle(request);
        List<String> title = Arrays.asList("访客数", "下单人数", "付款人数", "付款金额", "申请人数", "付全款人数", "访客-下单转化率", "访问-付款转化率", "下单-付款转化率", "项目访问总数-申请转化率", "申请-付全款转化率");
        List<List<Object>> rows = new ArrayList<>();
        List<Object> list = new ArrayList<>();
        list.add(response.getVisit());
        list.add(response.getOrder());
        list.add(response.getPayNum());
        list.add(response.getPayAmount());
        list.add(response.getApplyNum());
        list.add(response.getPayAllNum());
        list.add(response.getVisitOrder());
        list.add(response.getVisitPay());
        list.add(response.getOrderPay());
        list.add(response.getProjectVisitApply());
        list.add(response.getApplyPayAll());
        rows.add(list);
        ExcelData excelData = new ExcelData();
        excelData.setName("交易概况");
        excelData.setRows(rows);
        excelData.setTitles(title);
        ExcelUtil.exportExcel(getHttpServletResponse(), "交易概况", excelData);

        return new EmptyResponse();
    }
}
